<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>点击停止定时器</button>
    <script>
      var btn = document.querySelector('button');
      var time = setTimeout(function () {
        alert('蹦沙卡拉卡');
      }, 3000);
      //点击按钮关闭定时炸弹
      btn.addEventListener('click', function () {
        //清除定时器
        clearTimeout(time);
      });
    </script>
  </body>
</html>
